package com.example.ruoyiakp.agricul.controller;

import com.example.ruoyiakp.agricul.domain.AgrAgriculturalSupplies;
import com.example.ruoyiakp.agricul.service.IAgrAgriculturalSuppliesService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 农资管理Controller
 *
 * @author pby
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/supplies")
public class AgrAgriculturalSuppliesController extends BaseController {
    @Autowired
    private IAgrAgriculturalSuppliesService agrAgriculturalSuppliesService;


    /**
     * 查询农资管理列表
     */
    @RequiresPermissions("system:supplies:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrAgriculturalSupplies agrAgriculturalSupplies) {
        startPage();
        List<AgrAgriculturalSupplies> list = agrAgriculturalSuppliesService.selectAgrAgriculturalSuppliesList(agrAgriculturalSupplies);
        return getDataTable(list);
    }

    /**
     * 导出农资管理列表
     */
    @RequiresPermissions("system:supplies:export")
    @Log(title = "农资管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgrAgriculturalSupplies agrAgriculturalSupplies) {
        List<AgrAgriculturalSupplies> list = agrAgriculturalSuppliesService.selectAgrAgriculturalSuppliesList(agrAgriculturalSupplies);
        ExcelUtil<AgrAgriculturalSupplies> util = new ExcelUtil<AgrAgriculturalSupplies>(AgrAgriculturalSupplies.class);
        util.exportExcel(response, list, "农资管理数据");
    }

    /**
     * 获取农资管理详细信息
     */
    @RequiresPermissions("system:supplies:query")
    @GetMapping(value = "/{suppId}")
    public AjaxResult getInfo(@PathVariable("suppId") Long suppId) {
        return success(agrAgriculturalSuppliesService.selectAgrAgriculturalSuppliesBySuppId(suppId));
    }

    /**
     * 新增农资管理
     */
    @RequiresPermissions("system:supplies:add")
    @Log(title = "农资管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgrAgriculturalSupplies agrAgriculturalSupplies) {
        return toAjax(agrAgriculturalSuppliesService.insertAgrAgriculturalSupplies(agrAgriculturalSupplies));
    }

    /**
     * 修改农资管理
     */
    @RequiresPermissions("system:supplies:edit")
    @Log(title = "农资管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgrAgriculturalSupplies agrAgriculturalSupplies) {
        return toAjax(agrAgriculturalSuppliesService.updateAgrAgriculturalSupplies(agrAgriculturalSupplies));
    }

    /**
     * 删除农资管理
     */
    @RequiresPermissions("system:supplies:remove")
    @Log(title = "农资管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{suppIds}")
    public AjaxResult remove(@PathVariable Long[] suppIds) {
        return toAjax(agrAgriculturalSuppliesService.deleteAgrAgriculturalSuppliesBySuppIds(suppIds));
    }
}
